package app.itgungnir.compose.wan.business.splash

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.itgungnir.compose.wan.utils.LocalDataStore
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch

class SplashViewModel : ViewModel() {

    val jumpState = MutableStateFlow<Pair<Int, Int>?>(null)

    init {
        if (LocalDataStore.localData.hasLaunched) {
            jump()
        }
    }

    fun jump() = viewModelScope.launch {
        LocalDataStore.updateLocalData {
            it.hasLaunched = true
        }
        val colorPalette = LocalDataStore.localData.themePaletteIndex
        val fontTypography = LocalDataStore.localData.fontTypographyIndex
        jumpState.value = colorPalette to fontTypography
    }
}
